package com.bee.common.core.result;

/**
 * Created by liekkas on 2017-8-1.
 * 接口返回类
 */
public class Result<T> {

	//请求信息
	private int code;
	//结果信息
	private String msg;
	//请求结果
	private T obj;
		
	public Result(int code, String msg, T obj) {
		super();
		this.code = code;
		this.msg = msg;
		this.obj = obj;
	}
		
	public static Result success(String msg,Object obj){
		return new Result(ResultCode.SUCCESS.getCode(),msg,obj);
	}

	public static Result success(Object obj){
		return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.toString(),obj);
	}
	
	public static Result success(String msg){
		return new Result(ResultCode.SUCCESS.getCode(),msg,null);
	}
	
	public static Result success(){
		return success(null);
	}
	
	public static Result fail(){
		return fail(null);
	}
	
	public static Result fail(String msg){
		return new Result(ResultCode.FAIL.getCode(),msg,null);
	}
	
	public static Result fail(String msg,Object obj){
		return new Result(ResultCode.FAIL.getCode(),msg,obj);
	}
	
	public static Result fail(Object obj){
		return new Result(ResultCode.FAIL.getCode(),ResultCode.FAIL.toString(),obj);
	}

	public static Result invalid(){
		return new Result(ResultCode.INVALID.getCode(),ResultCode.INVALID.getMessage(),null);
	}
	
	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getObj() {
		return obj;
	}
	public void setObj(T obj) {
		this.obj = obj;
	}
}
